<!DOCTYPE html>
<html>
<head>
    <title>用户管理</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">商店名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <a id='getmap'>添加经纬度</a>
                    </label>
                    <div class="layui-input-inline" style="display: inline-flex;width: 400px;">
                        <span style="width: 60px;display: inline-flex;align-items: center;">经度</span>
                        <input
                                type="text" name="lngname" required
                                lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入经度"
                                value="{{ lng }}">
                        <span style="width: 60px;display: inline-flex;align-items: center;margin-left: 10px;">纬度</span>
                        <input
                                type="text" id="username" name="latname" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" placeholder="请输入纬度" value="{{ lat }}">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">商店介绍</label>
                    <div class="layui-input-block">
                        <input type="text" name="shopcontent" lay-verify="pass" autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">商店标语</label>
                    <div class="layui-input-block">
                        <input type="text" name="shopslogan" lay-verify="title" autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>


                <fieldset class="layui-elem-field layui-field-title" style="margin: -8px 0px 10px 10px;">
                    <legend>商店图片</legend>
                </fieldset>
                <div class="layui-upload-drag" id="uptest"
                     style="width: 70px; display: inline-block;margin-left: 40px;">
                    <i class="layui-icon"></i>
                    <p>点击上传，或将文件拖拽到此处</p>
                </div>
                <div id="uploadDemoView">

                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
<script>
    layui.use(['upload', 'form', 'jquery'], function () {
        let form = layui.form
        let $ = layui.jquery
        let upload = layui.upload
        let imgpath = ''


        //拖拽上传
        upload.render({
            elem: '#uptest'
            , url: '{{ url_for('wxstores.upphoto') }}' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            {#,url: 'https://httpbin.org/post'#}
            , exts: 'jpg|png|gif|bmp|jpeg'
            , done: function (res) {
                layer.msg('上传成功', {icon: 1});
                {#console.log(res.img)#}
                let html = " <img src='" + res.data.src + "' alt='上传成功后渲染' style='max-width: 103px;position: relative;margin-left: 190px;margin-top: -143px;display: inline-block'>"
                layui.$('#uploadDemoView').append(html)
                {#find('img').attr('src', res.data.src);#}
                imgpath = res.data.src
                console.log(imgpath)
                {#layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);#}
                console.log(res)
            }
        });


        form.on('submit(user-save)', function (data) {
            {#let roleIds = ''#}
            {#$('input[type=checkbox]:checked').each(function () {#}
            {#    roleIds += $(this).val() + ','#}
            {#//})#}
            {#roleIds = roleIds.substr(0, roleIds.length - 1)#}
            {#data.field.roleIds = roleIds#}
            console.log(data.field)
            data.field.file = imgpath
            $.ajax({
                url: '/wxstores/addstores',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
                            parent.layui.table.reload('user-table')
                        })
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000})
                    }
                }
            })
            return false
        })


        $("#getmap").click(function () {
            window.add()
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增商品',
                shade: 0.1,
                area: ['550px', '350px'],
                content: '/wxstores/addmap'
            })
        }

    })
</script>
<script>
</script>
</body>
</html>